package com.immunology.service;

import java.sql.Date;
import java.util.Map;

import com.immunology.dao.PatientDao;
import com.immunology.database.transformers.PatientTransformer;
import com.immunology.model.Patient;
import com.immunology.model.enums.Gender;

public class CreatePatientService {

	public Patient createPatient(Map<String, String> parameters) {
		Patient patient = new Patient();
		patient.setFirstName(parameters.get("firstName"));
		patient.setMiddleName(parameters.get("middleName"));
		patient.setLastName(parameters.get("lastName"));
		patient.setGender(Gender.fromValue(parameters.get("gender")));
		Date birthday = new Date(1);
		birthday.setDate(Integer.parseInt(parameters.get("day")));
		birthday.setMonth(Integer.parseInt(parameters.get("month")));
		birthday.setYear(Integer.parseInt(parameters.get("year"))-1900);
		patient.setBirthday(birthday);
		patient.setCountry(parameters.get("country"));
		patient.setRegion(parameters.get("region"));
		patient.setDistrict(parameters.get("district"));
		patient.setCity(parameters.get("city"));
		patient.setStreet(parameters.get("street"));
		patient.setHouse(parameters.get("house"));
		patient.setFlat(parameters.get("flat"));
		PatientDao patientDao = new PatientDao(new PatientTransformer());
		patientDao.insert(patient);
		return patient;
	}
}
